package com.gduf.lsm.controller;

import com.gduf.lsm.common.Result;
import com.gduf.lsm.entity.Examine;
import com.gduf.lsm.pojo.dto.JoinStatusDTO;
import com.gduf.lsm.pojo.vo.ExamineShowVO;
import com.gduf.lsm.pojo.vo.MentalShowVO;
import com.gduf.lsm.service.ExamineService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 心理健康信息表前端操作接口
 **/
@RestController
@RequestMapping("/examine")

public class ExamineController {

    @Resource
    private ExamineService examineService;

    /**
     * 新增
     * @param examine
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Examine examine) {
        int examineId=examineService.add(examine);
        System.out.println("**************"+examineId);
        return Result.success(examineId);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        examineService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        examineService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     * @param examine
     * @return
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Examine examine) {
        examineService.updateById(examine);
        return Result.success();
    }

    /**
     * 修改活动状态
     * @param joinStatusDTO
     * @return
     */
    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody JoinStatusDTO joinStatusDTO){
        examineService.updateStatus(joinStatusDTO);
        return Result.success();
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Examine examine = examineService.selectById(id);
        return Result.success(examine);
    }

    /**
     * 查询所有
     * @param examine
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll(Examine examine ) {
        List<Examine> list = examineService.selectAll(examine);
        return Result.success(list);
    }

    /**
     * 查询单个所有
     * @param id
     * @return
     */
    @GetMapping("/selectAllById/{id}")
    public Result selectAllById(@PathVariable Integer id){
        ExamineShowVO examineShowVO=examineService.selectAllById(id);
        return Result.success(examineShowVO);
    }

    /**
     * 查询用户的心理健康表
     * @param userId
     * @return
     */
    @GetMapping("selectByUserId/{userId}")
    public Result selectByUserId(@PathVariable Integer userId){
        List<ExamineShowVO> list=examineService.selectByUserId(userId);
        return Result.success(list);
    }

    /**
     * 分页查询
     * @param examine
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPage")
    public Result selectPage(Examine examine,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<ExamineShowVO> page = examineService.selectPage(examine, pageNum, pageSize);
        return Result.success(page);
    }

}